"""
Copyright 2009, Thomas Dejanovic, Jay Shurtz.
 
This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.

This is the most specific level of verilog generation for register
hatchlings.  it contains information about how to generate and
write verilog from the hatchling data structure.
"""

id = "$Id: hatch_verilog.py 667 2010-07-01 00:12:17Z jayshurtz $"
# $URL: http://hatch.googlecode.com/svn/trunk/hatch/hatch_targets/hatch_verilog.py $
# $Author: jayshurtz $
version = " ".join(id.split()[1:3])


from os import extsep
import to_hatch_structure
from hatch_log import *
from hatch_constants import VERILOG_FILE_HEADER
from verilog_net_dict  import *
from verilog_generator import VerilogNode


# print logger
# raw_input("hatch verilog - hit enter to continue.")

def generate(hatchNode, moduleName):
    """ 
    """
    # logger.info(generate.func_name + "(" + hatchNodeClassAndName(hatchNode) + ", " + str(moduleName) + ")")
    vn = VerilogNode(hatchNode)
    outputFile = open(moduleName + ".v", 'w')
    outputFile.write(VERILOG_FILE_HEADER)
    outputFile.write(vn.code())  # Write to file.  
    outputFile.close()

    # write out #defines for the register addresses.
    outputFile = open(moduleName + ".vh", 'w')
    outputFile.write(VERILOG_FILE_HEADER)
    outputFile.write(vn.address_defines())  # Write to file.  
    outputFile.close()


# TODO - built-in-self-test 
if __name__ == "__main__":

    consoleHandler.setLevel(logging.DEBUG)


